package com.sgb.kjwl.view.ui.adapter.home;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.transport.GoodsInfoEntity;
import com.sgb.kjwl.utils.NumberUtil;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.StringUtil;

import java.util.List;

public class HomeSourceOfSupplyAdapter extends BaseRecycleAdapter<GoodsInfoEntity> {

    public HomeSourceOfSupplyAdapter(Context context, List<GoodsInfoEntity> datas) {
        super(context, R.layout.item_source_of_supply1, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final GoodsInfoEntity entity) {
        holder.setBinding(BR.viewModel, entity);

        TextView textView = holder.getItem().findViewById(R.id.tv_distance);
        TextView tvTag = holder.getItem().findViewById(R.id.tv_tag);
        TextView tvType = holder.getItem().findViewById(R.id.company_view);
        TextView price_view = holder.getItem().findViewById(R.id.price_view);
        TextView title_view = holder.getItem().findViewById(R.id.title_view);
        if (entity.getShipmentEndTime() == null){
            tvType.setText("可装货时间:" + DateUtils.timestampTo13DateNos(entity.getShipmentTime()));
        }else {
            tvType.setText("可装货时间:" + DateUtils.timestampTo13DateNos(entity.getShipmentTime()) + "-" + DateUtils.timestampTo13DateNos(entity.getShipmentEndTime()));
        }
        if (entity != null) {
            if (TextUtils.isEmpty(entity.getDistance())) {
                textView.setText("");
            } else {
                textView.setText(Double.valueOf(entity.getDistance()) < 1000 ? "1km以内" : StringUtil.fromatUpDistance(entity.getDistance()) + "KM");
            }
            if (entity.getPattern() == 0) {
                tvTag.setVisibility(View.GONE);
            } else {
                tvTag.setVisibility(View.VISIBLE);
            }
        }

        String wightStr = (TextUtils.isEmpty(entity.getWeight()) || TextUtils.isDigitsOnly(entity.getWeight()) ? "" : "/" + NumberUtil.trim0(entity.getWeight()) + "吨");
        String volumeStr = TextUtils.isEmpty(entity.getVolume()) ? "" : "/" + NumberUtil.trim0(entity.getVolume()) + "方";
        title_view.setText(entity.getGoodsModeName() + wightStr + volumeStr);

        if (entity.getFreightType() == 1) {
            price_view.setText("运费 电议");
        } else {
            price_view.setText(!entity.getAllFreight().isEmpty() ? "运费: " + NumberUtil.trim0(entity.getAllFreight()) + "元" : "");
        }
    }

}

